﻿using System.Collections.Generic;
using System.Linq;
using Configuration;
using Model;
using Repository.Common;

namespace Repository
{
    public class tkntCategoryRepository : Repository<tkntCategory>
    {
        public tkntCategoryRepository(Database context)
            : base(context)
        {
        }

        public tkntCategory HaveProduct(int id)
        {
            GetContext().ContextOptions.LazyLoadingEnabled = true;
            var res = (from c in GetQuery().Include("Products") where c.Id == id select c).SingleOrDefault();

            return res;
        }

        public List<tkntCategory> SearchByName(string name, string locale)
        {
            var res = new List<tkntCategory>();
            if (locale.ToLower() == "vi")
                res = (from c in GetQuery() where c.ViName.ToLower().Contains(name.ToLower()) select c).ToList();
            else
                res = (from c in GetQuery() where c.EnName.ToLower().Contains(name.ToLower()) select c).ToList();

            return res;
        }
    }
}